//
//  ChatTableViewCell.m
//  projectOfTeamSample
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 liukai. All rights reserved.
//

#import "ChatTableViewCell.h"



@implementation ChatTableViewCell
#pragma mark -- 数据
- (void)getsourarray{
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"weixin",@"name",@"微信团队欢迎你。很高兴你开启了微信生活，期待能为你和朋友们带来愉快的沟通。",@"content", nil];
    NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"hello",@"content", nil];
   
    NSDictionary *dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"weixin",@"name",@"谢谢反馈，已收录。",@"content", nil];
    
    NSDictionary *dict5 = [NSDictionary dictionaryWithObjectsAndKeys:@"weixin",@"name",@"谢谢反馈，已收录。",@"content", nil];
    NSDictionary *dict6 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试，长数据测试，大数据测试，长数据测试，大数据测试，长数据测试，大数据测试，长数据测试，大数据测试，长数据测试。",@"content", nil];
    NSDictionary *dict7 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict9 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict0 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict11 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict12 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict13 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict14 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict15 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict16 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict17 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict18 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict19 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
     NSDictionary *dict10 = [NSDictionary dictionaryWithObjectsAndKeys:@"rhl",@"name",@"大数据测试，长数据测试，大数据测试",@"content", nil];
    self.array = [[NSArray alloc]init];
   self.array = [NSArray arrayWithObjects:dict,dict1,dict3,dict5,dict6,dict7,dict8,dict9,dict0,dict11,dict12,dict13,dict14,dict15,dict16,dict17,dict18,dict19,dict10, nil];
   
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //聊天的信息
      //  [self setupSubView];
        //数据
        [self getsourarray];
    }
    return self;
}

- (void)setupSubView{
    //设置用户的头像
    self.userHeadImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width - 55, 5, 50, 50)];
    self.userHeadImage.layer.cornerRadius = 10;
    self.userHeadImage.layer.masksToBounds = YES;
    
    //设置用户的文字
    }

#pragma mark -- 泡泡文字
/**
 *泡泡文字
 *@ text 输入的文字
 *@ position 位置
 **/

- (UIView *)bubbleViewWithText:(NSString *)text form:(BOOL)fromSelf withPosition:(int)position{
    
    //计算大小
    UIFont *font = [UIFont systemFontOfSize:14];
    CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(180.0f, 20000.0f)];
    //
    UIView *returnView = [[UIView alloc]initWithFrame:CGRectZero];
    returnView.backgroundColor = [UIColor clearColor];
    
    //背景图片
    UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:fromSelf ? @"SenderAppNodeBkg_HL":@"ReceiverTextNodeBkg" ofType:@"png"]];
    
    UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:[bubble stretchableImageWithLeftCapWidth:floorf(bubble.size.width /2 ) topCapHeight:floorf(bubble.size.height / 2)]];
    
    UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(fromSelf ? 15.0f : 22.0f, 20.f, size.width + 10, size.height + 10)];
    bubbleText.backgroundColor = [UIColor clearColor];
    bubbleText.font = font;
    bubbleText.numberOfLines = 0 ;
    bubbleText.lineBreakMode = NSLineBreakByWordWrapping;
    bubbleText.text = text;
    
    bubbleImageView.frame = CGRectMake(0, 14, bubbleText.frame.size.width + 30, bubbleText.frame.size.height +20);
    
    if(fromSelf)
        returnView.frame = CGRectMake(self.contentView.bounds.size.width-position-(bubbleText.frame.size.width+30.0f), 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
    else
        returnView.frame = CGRectMake(position, 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
    
    [returnView addSubview:bubbleImageView];
    [returnView addSubview:bubbleText];
    
    return returnView;

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
